const express = require('express');
const app = express();
app.use(express.json())
app.use(express.urlencoded({ extended: true })) 

// 设置 Mongoose 连接
const mongoose = require('mongoose');
const router = require('./routes/indexRouter');
const mongoDB = 'mongodb://ssmAdmin:root@106.13.21.72:27017/ssm?authMechanism=DEFAULT&authSource=ssm';
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.Promise = global.Promise;
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB 连接错误：'));
db.once('open', function () {
    console.log("open");
});
db.once('close', function () {
    console.log("close");
});

app.use("/", router);

app.listen(8080, () => {
    console.log('Run at http://localhost:8080');
});